﻿#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System;
using Microsoft.Xna.Framework.Content;
using RhinoXNA.RhinoGraphics.Rhino2D;
#endregion

namespace RhinoXNA
{
    public class RhinoXNAAdapter
    {
        private Rectangle _screenSafe;
        private float _aspect;

        private ContentManager _content;

        public Rectangle SCREEN_SAFE { get { return _screenSafe; } }
        public float AspectRatio { get { return _aspect; } }

        private ILevel _level;
        private IMenu _menu;

        private SpriteBatch _sBatch;

        private Random _rand;

        public ILevel Level
        {
            get { return _level; }
        }

        public IMenu Menu
        {
            get { return _menu; }
        }

        public ContentManager ContentManager
        {
            get { return _content; }
        }

        public SpriteBatch SpriteBatch
        {
            get { return _sBatch; }
        }

        public RhinoXNAAdapter(ContentManager content, GraphicsDeviceManager graphics, SpriteBatch sBatch, int screenWidth, int screenHeight)
        {
            graphics.PreferredBackBufferWidth = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;
            graphics.ApplyChanges();

            _aspect = graphics.GraphicsDevice.Viewport.AspectRatio;
            _screenSafe = graphics.GraphicsDevice.Viewport.TitleSafeArea;

            _content = content;
            _sBatch = sBatch;

            _rand = new Random();
        }

        public void AddNewLevel(ILevel level)
        {
            _level = level;
        }

        public void AddNewMenu(IMenu menu)
        {
            _menu = menu;
        }

        public void DrawLevel()
        {
            if (_level != null)
            {
                _level.Render();
            }
            else
            {
                throw new NullReferenceException("RhinoXNAAdapter ERROR: Current Level is null; cannot draw");
            }
        }

        public void DrawMenu()
        {
            if (_menu != null)
            {
                _menu.Render();
            }
            else
            {
                throw new NullReferenceException("RhinoXNAAdapter ERROR: Current Menu is null; cannot draw");
            }

        }

        public int RandomInt(int min, int max)
        {
            return _rand.Next(min, max);
        }
    }
}
